package arcsoft.android.record;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

import javax.swing.JOptionPane;



public class Record {
	
	public static void main(String[] args){
		int event1count=0;
		try{
			File rFile = new File("EventNotes.txt");
			File wFile = new File("EventNotes.bat");
			BufferedReader br = new BufferedReader(new FileReader(rFile));
			BufferedWriter bw = new BufferedWriter(new FileWriter(wFile,true));
			
			String tempStr = br.readLine();tempStr = br.readLine();// read a line
			while(tempStr!=null){
				String newLine = null;
				if('/'==tempStr.charAt(0)){
					int num1 = Dec4(DecNum(tempStr.charAt(19)))+Dec3(DecNum(tempStr.charAt(20)))+Dec2(DecNum(tempStr.charAt(21)))+Dec1(DecNum(tempStr.charAt(22)));
					int num2 = Dec4(DecNum(tempStr.charAt(24)))+Dec3(DecNum(tempStr.charAt(25)))+Dec2(DecNum(tempStr.charAt(26)))+Dec1(DecNum(tempStr.charAt(27)));
					int num3 = Dec8(DecNum(tempStr.charAt(29)))+Dec7(DecNum(tempStr.charAt(30)))+Dec6(DecNum(tempStr.charAt(31)))+Dec5(DecNum(tempStr.charAt(32)))
					          +Dec4(DecNum(tempStr.charAt(33)))+Dec3(DecNum(tempStr.charAt(34)))+Dec2(DecNum(tempStr.charAt(35)))+Dec1(DecNum(tempStr.charAt(36)));
					int event = DecNum(tempStr.charAt(16));
					switch(event){
					case 0:
						switch(event1count){
						case 0:
							if(num1==3&&num2==0){
								newLine=newStringLine(event,num1,num2,num3);
								event1count=1;
							}
							break;
						case 1:
							if(num1==3&&num2==1){
								newLine=newStringLine(event,num1,num2,num3);
								event1count=2;
							}
							break;
						case 2:
							if(num1==1&&num2==330&&num3==1){
								newLine=newStringLine(event,num1,num2,num3);
								event1count=3;
							}
							break;
						case 3:
							if(num1==0&&num2==0&&num3==0){
								newLine=newStringLine(event,num1,num2,num3);
								event1count=4;
							}
							break;
						case 4:
							if(num1==1&&num2==330&&num3==0){
								newLine=newStringLine(event,num1,num2,num3);
								event1count=5;
							}
							break;
						case 5:
							if(num1==0&&num2==0&&num3==0){
								newLine=newStringLine(event,num1,num2,num3);
								event1count=0;
							}
							break;
						default:
							break;
						}
						break;
					case 2:
						newLine=newStringLine(event,num1,num2,num3);
						break;
					case 3:
						newLine=newStringLine(event,num1,num2,num3);
						break;
					case 4:
						break;
					default:
						break;
					}
					
				}
				else tempStr=null;
				if(newLine!=null){bw.append(newLine);bw.newLine();bw.flush();}
				tempStr = br.readLine();
				tempStr = br.readLine();
			}
			bw.close();
			br.close();
			JOptionPane.showMessageDialog(null,"Success Done");
		}catch(Exception e){JOptionPane.showMessageDialog(null,e);};
		
	}
	static int DecNum(char a){
		if(a=='0')return 0;
		if(a=='1')return 1;
		if(a=='2')return 2;
		if(a=='3')return 3;
		if(a=='4')return 4;
		if(a=='5')return 6;
		if(a=='6')return 6;
		if(a=='7')return 7;
		if(a=='8')return 8;
		if(a=='9')return 9;
		if(a=='A'||a=='a')return 10;
		if(a=='B'||a=='b')return 11;
		if(a=='C'||a=='c')return 12;
		if(a=='D'||a=='d')return 13;
		if(a=='E'||a=='e')return 14;
		else return 15;		
	}
	static int Dec8(int x){
		x=16*16*16*16*16*16*16*x;
		return x;
	}
	static int Dec7(int x){
		x=16*16*16*16*16*16*x;
		return x;
	}
	static int Dec6(int x){
		x=16*16*16*16*16*x;
		return x;
	}
	static int Dec5(int x){
		x=16*16*16*16*x;
		return x;
	}
	static int Dec4(int x){
		x=16*16*16*x;
		return x;
	}
	static int Dec3(int x){
		x=16*16*x;
		return x;
	}
	static int Dec2(int x){
		x=16*x;
		return x;
	}
	static int Dec1(int x){
		return x;
	}
	
	static String newStringLine(int event,int x,int y, int z){
		String newLine="adb shell sendevent /dev/input/event"+String.valueOf(event)+" "+String.valueOf(x)+" "+String.valueOf(y)+" "+String.valueOf(z);
		return newLine;
	}
}